package org.example.project.controller;

import org.example.project.entity.Comment;
import org.example.project.service.CommentService;
import org.example.project.util.ResponseCode;
import org.example.project.util.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 岩
 * @Package org.example.project.controller
 * @Project MyApp
 * @Name CommentController
 * @Date 2024-04-27 20:05
 * @Filename CommentController
 */

@RestController
@RequestMapping("/comments")
public class CommentController {
    @Resource
    private CommentService commentService;

    @GetMapping
    public ResponseData queryAllComments(@RequestParam("postId") int postId) {
        return new ResponseData(ResponseCode.success, this.commentService.queryAll(postId));
    }

    @GetMapping("/getCommentById")
    public ResponseData getCommentById(@RequestParam("commentId") int commentId) {
        return new ResponseData(ResponseCode.success, this.commentService.queryById(commentId));
    }

    @PostMapping
    public ResponseData publishComment(@RequestBody Comment comment) {
        return new ResponseData(ResponseCode.success, this.commentService.publish(comment));
    }

    @DeleteMapping
    public ResponseData deleteComment(@RequestParam("commentId") int commentId) {
        return new ResponseData(ResponseCode.success, this.commentService.delete(commentId));
    }

    @PutMapping("/likeComment")
    public ResponseData likeComment(@RequestParam("commentId") int commentId) {
        return new ResponseData(ResponseCode.success, this.commentService.like(commentId));
    }
}
